<template>
  <div>
    <div>{{isLogining ? '加载中' : '加载结束'}}</div>
    <div>
      <img :src="qrcode" v-for="qrcode in qrcodes">
    </div>
  </div>
</template>

<script>
  import global from '../lib/global'
  import axios from 'axios'

  export default {
    data() {
      return {
        qrcodes: [],
        isLogining: true
      }
    },
    mounted() {
      this.$store.commit('set_title', '登录wechat')

      if (!this.$store.state.admin) {
        this.$router.goback()
        return
      }

      axios.post(global.server + 'loginWehcat.do', {}).then(result => {
        this.isLogining = false
      }, result => {
        this.isLogining = false
      })
      this.getWechatLoginQrcode()
    },
    methods: {
      getWechatLoginQrcode() {
        axios.post(global.server + 'getWechatLoginQrcode.do', {}).then(result => {
          const obj = result.data
          this.qrcodes = []
          obj.qrcodes.forEach(qrcode => {
            this.qrcodes.push('data:image/png;base64,' + qrcode)
          })
        }, result => {
        })
        if(this.isLogining) {
          setTimeout(() => {
            this.getWechatLoginQrcode()
          }, 1000)
        }
      }
    }
  }
</script>
